﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using CivilleWP7.CivilleDataServiceReference;
using System.Windows.Media.Imaging;

namespace CivilleWP7.Views.Controls
{
    public partial class TaskTileControl : UserControl
    {
        private Task task;

        public Task Task
        {
            get { return task; }
            set 
            { 
                task = value;
                var myBrush = new ImageBrush();
                if (task.TaskTypeID == 2)
                {
                    //BitmapImage image = new BitmapImage(new Uri("/Resources/Images/diamond.jpg", UriKind.Relative));
                    //myBrush.ImageSource = image;
                }
                if (task.TaskTypeID == 1)
                {
                    //BitmapImage image = new BitmapImage(new Uri("/Resources/Images/carbon.jpg", UriKind.Relative));
                    //myBrush.ImageSource = image;
                }
                //LayoutRoot.Background = (SolidColorBrush)App.Current.Resources["PhoneAccentBrush"];
                Brush backBrush = new LinearGradientBrush();
                backBrush.SetValue(LinearGradientBrush.EndPointProperty, new Point(10.5, 10.5));
                backBrush.SetValue(LinearGradientBrush.MappingModeProperty, BrushMappingMode.Absolute);
                backBrush.SetValue(LinearGradientBrush.SpreadMethodProperty, GradientSpreadMethod.Repeat);
                backBrush.SetValue(LinearGradientBrush.StartPointProperty, new Point(0, 0));
                
                GradientStop gs1 = new GradientStop();
                gs1.Color = (Color)App.Current.Resources["PhoneAccentColor"];
                GradientStop gs2 = new GradientStop();
                gs2.Color = (Color)App.Current.Resources["PhoneAccentColor"];
                GradientStop gs3 = new GradientStop();
                gs2.Offset = 0.526;
                Color col1 = (Color)App.Current.Resources["PhoneAccentColor"];
                col1.A = 200;
                gs3.Color = col1;
                gs3.Offset = 0.544;
                GradientStop gs4 = new GradientStop();
                gs4.Color = col1;
                gs4.Offset = 1;
                GradientStopCollection gsc = new GradientStopCollection();
                gsc.Add(gs1);
                gsc.Add(gs2);
                gsc.Add(gs3);
                gsc.Add(gs4);
                backBrush.SetValue(LinearGradientBrush.GradientStopsProperty, gsc);
                LayoutRoot.Background = backBrush;
            }
        }
        public TaskTileControl()
        {
            InitializeComponent();
            this.Loaded += new RoutedEventHandler(TaskTileControl_Loaded);
        }

        void TaskTileControl_Loaded(object sender, RoutedEventArgs e)
        {
 
        }
    }
}
